<template>
    <div class="hello">
        <div>
            <label for="">姓名</label>
            <input type="text"
                v-model="userName">
            <button @click="login">登录</button>
        </div>
        <div>
            <label for="">输入内容</label>
            <input type="text"
                v-model="content">
            <button @click="setContent">发送</button>
        </div>
        <ul>
            <li v-for="(item,index) in getClientContentList"
                :key="index">
                {{item.content}}
            </li>
        </ul>
    </div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex';
export default {
  name: 'HelloWorld',
  data() {
    return {
      userName: '',
      content: '',
      massage: []
    };
  },
  methods: {
    ...mapActions(['addClientContentList']),
    login() {
      if (this.userName) {
      } else {
        alert('请输入名称');
      }
    },
    setContent() {
      if (this.content) {
        this.addClientContentList(this.content);
        this.content = '';
      } else {
        alert('请输入内容');
      }
    }
  },
  created() {},
  computed: {
    ...mapGetters({
      getClientContentList: 'getClientContentList'
    })
  },
  components: {}
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1,
h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
